"use server";

import myUndelPostsService from "@/server/service/post/my-undel-posts-service";
import { PostSummary } from "@/shared/types";
import { cookies } from "next/headers";
import { checkPageAndSize } from "@/server/utils";
import { wrapAction } from "@/server/wrapper";
import { getSessionFromNextCookies } from "@/server/service/session-service";

export async function getMyPosts(page: number, size: number) {
  return await wrapAction(async (): Promise<{ posts: PostSummary[]; count: number }> => {
    checkPageAndSize(page, size);
    const session = await getSessionFromNextCookies(cookies())
    const me = await session.getMe()

    return await myUndelPostsService.pageGetPostSummary(me, page, size);
  });
}
